﻿using Newtonsoft.Json;

namespace MBA.FluentExt.Converters
{
	public sealed class JsonConfigValueConverter : JsonConverter
	{
		#region Methods

		public override bool CanConvert(System.Type objectType)
		{
			return objectType.Equals(typeof(Raw));
		}

		public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
		{
			throw new System.NotImplementedException();
		}

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var config = (Raw)value;

			if(config.RawValue)
			{
				writer.WriteRawValue(config.Value.ToString());
			}
			else
			{
				writer.WriteValue(config.Value);
			}
		}

		#endregion Methods
	}
}